package com.atguigu.serviceAuth.controller;

import com.atguigu.commonutil.ApiResponse;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalTime;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Aug28-tlsjn
 * @date 2020-09-20 Sunday 14:59
 */
@RestController
@RequestMapping(value = {"/auth"})
@CrossOrigin
public class AuthController {

    @RequestMapping(value = { "/user/login" }, method = { RequestMethod.POST, RequestMethod.OPTIONS })
    public ApiResponse<Map<String, Object>> handleLogin() {
        Map<String, Object> map = new HashMap<>(1);
        map.put("token", System.currentTimeMillis());
        return ApiResponse.successInstance().setData(map);
    }

    @RequestMapping(value = { "/user/info" }, method = { RequestMethod.GET, RequestMethod.OPTIONS })
    public ApiResponse<Map<String, Object>> userInfo() {
        Map<String, Object> map = new HashMap<>(1);
        map.put("name", "LocalTime.now()");
        map.put("avatar", "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1600598119463&di=49b89e3722c671f45e28091424b0f61e&imgtype=0&src=http%3A%2F%2Fimgsrc.baidu.com%2Fforum%2Fw%3D580%2Fsign%3Dba5a5248a0014c08193b28ad3a7a025b%2Fb00db07eca8065385fa97bf29edda144ac3482aa.jpg");
        return ApiResponse.successInstance().setData(map);
    }

    @RequestMapping(value = { "/user/logout" }, method = { RequestMethod.POST, RequestMethod.OPTIONS })
    public ApiResponse<Map<String, Object>> handleLogout() {
        Map<String, Object> map = new HashMap<>(1);
        map.put("token", LocalTime.now());
        return ApiResponse.successInstance().setData(map);
    }
}
